//Accepted
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int a, b, c, d, x, y, i;
int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	scanf("%d%d%d%d", &a, &b, &c, &d);
	while(a+b+c+d){
		for(y=0,i=b;i!=d;){
			++y;
			++i;
			if(i==60){
				a=(a+1)%24;
				i=0;
			}
		}
		for(x=0,i=a;i!=c;i=(i+1)%24)++x;
		
		printf("%d\n", (x*60+y));
		
		scanf("%d%d%d%d", &a, &b, &c, &d);
	}
	return 0;
}
